import { formatMenu } from './index'

import router from '@/router'

export default function addRoutes() {
  let menu = localStorage.getItem('menu')
  if (menu) {
    menu = formatMenu(JSON.parse(menu))
    function addRoute(menu) {
      menu.forEach((item) => {
        if (item.ifLink != 1) {
          router.addRoute(item)
        }
        if (item.subPermissionList && item.subPermissionList.length > 0) {
          addRoute(item.subPermissionList)
        }
      })
    }
    addRoute(menu)
  }
}
